//
//  ZMyOrderCarBottomView.m
//  DistributorAB
//
//  Created by LZY on 2019/10/11.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "ZMyOrderCarBottomView.h"

@implementation ZMyOrderCarBottomView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupViewAction];
        self.backgroundColor = kColorWithHex(0xffffff);
        //默认是购买类型
        self.btnType = ZMyOrderCarBottomViewClickTypeBuy;
    }
    return self;
}
#pragma mark - 界面布局
- (void)setupViewAction{
    UIButton *btnCycle = [UIButton buttonWithType:UIButtonTypeCustom];
    btnCycle.frame = CGRectMake(9, 13, 30, 30);
    [btnCycle setImage:imgname(@"cycle_normal_gray_icon") forState:UIControlStateNormal];
    [btnCycle setImage:imgname(@"cycle_selected_green_icon") forState:UIControlStateSelected];
    [btnCycle addTarget:self action:@selector(btnCycleClickAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btnCycle];
    self.btnSelect = btnCycle;
    
    UILabel *lblNotice = [[UILabel alloc] initWithFrame:CGRectMake(40, 13, 30, 30)];
    lblNotice.text = @"全选";
    lblNotice.font = [UIFont systemFontOfSize:14];
    lblNotice.textColor = kColorWithHex(0x484848);
    [self addSubview:lblNotice];
    
    UIButton *btnBuy = [UIButton buttonWithType:UIButtonTypeCustom];
    btnBuy.frame = CGRectMake(kScreen_Width - 188, 7, 170, 42);
    [btnBuy setImage:imgname(@"order_mall_order_submit_icon") forState:UIControlStateNormal];
    [btnBuy addTarget:self action:@selector(btnPayNowClickAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btnBuy];
    self.btnBuy = btnBuy;
}
//更新我要预订按钮
- (void)updateBtnBuy:(ZMyOrderCarBottomViewClickType)btnType{
    self.btnType = btnType;
    if (btnType == ZMyOrderCarBottomViewClickTypeBuy) {
        //我要预订
        [_btnBuy setImage:imgname(@"order_mall_order_submit_icon") forState:UIControlStateNormal];
    }else if (btnType == ZMyOrderCarBottomViewClickTypeDelete){
        //删除
        [_btnBuy setImage:imgname(@"order_mall_order_delete_icon") forState:UIControlStateNormal];
    }
    
    self.btnSelect.selected = NO;
    if (self.delegate && [self.delegate respondsToSelector:@selector(orderCarBottomViewClick:)]) {
        [self.delegate orderCarBottomViewClick:ZMyOrderCarBottomViewClickTypeNoneSelected];
    }
}
#pragma mark - 交互事件
//全选
- (void)btnCycleClickAction:(UIButton *)sender{
    if (self.delegate && [self.delegate respondsToSelector:@selector(orderCarBottomViewClick:)]) {
        if (self.btnSelect.selected) {
            self.btnSelect.selected = NO;
            [self.delegate orderCarBottomViewClick:ZMyOrderCarBottomViewClickTypeNoneSelected];
        }else{
            self.btnSelect.selected = YES;
            [self.delegate orderCarBottomViewClick:ZMyOrderCarBottomViewClickTypeSelected];
        }
    }
}
//我要预订
- (void)btnPayNowClickAction:(UIButton *)sender{
    if (self.delegate && [self.delegate respondsToSelector:@selector(orderCarBottomViewClick:)]) {
        [self.delegate orderCarBottomViewClick:self.btnType];
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
